import React, { Component } from 'react'
import './index.css'
import Time from '../../../until/getTime'
import axios from 'axios'

export default class Add extends Component {

 
    
    state =  this.props.item;

    submit = status =>{

        let submitData =   this.state;

        if(status === 'done'){
            submitData.sendTime = Time.getTimestamp();
            submitData.status   = 'done'
        }
       
       
        // 向后台发送数据
        axios.post(this.props.url,{submitData:submitData}).then(data=>alert(data.data.msg))
    }
    render() {
        console.log(this.props.item)
        const {type,title,ctx} = this.state
        return (
            <div className="add">
                <div className="form">消息类型
                    <select value={type} onChange={e=>this.setState({type:e.target.value})}>
                        <option value="系统消息">系统消息</option>
                        <option value="活动消息">活动消息</option>
                    </select>
                </div>   

                <div className="form">消息标题<input type="text" value={title}  onChange={e=>this.setState({title:e.target.value})}/></div>

                <div className="form">消息内容
                    <textarea value={ctx} onChange={e=>this.setState({ctx:e.target.value})}></textarea>
                </div>

                <div className="submit">
                    <span onClick={()=>this.props.setDefaultIndex(0)}>返回</span>
                    <span onClick={()=>this.submit('do')}>保存</span>
                    <span onClick={()=>this.submit('done')}>发布</span>
                </div>
            </div>
        )
    }

}
